﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Xml.Linq;

namespace TestExtensions
{
    public class TestIteration : IHasStatus, IEnumerable<TestAction>
    {
        #region Constructors

        public TestIteration(XElement iterationElement)
        {
            Element = iterationElement;
            IterationID = Element.Attribute("iterID").Value;
            this.LoadStatus();
            Actions = new ReadOnlyCollection<TestAction>(Element.Elements("Action").Select(actionElement => new TestAction(actionElement)).ToList());
        }

        #endregion

        #region Properties

        public XElement Element { get; private set; }

        public string IterationID { get; private set; }

        public string Status { get; set; }

        public ReadOnlyCollection<TestAction> Actions { get; private set; }

        #endregion

        #region Methods

        public IEnumerator<TestAction> GetEnumerator()
        {
            return Actions.GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return Actions.GetEnumerator();
        }

        #endregion
    }
}